package com.yanqu.road.server.manager.cricketcourt.log;

import com.yanqu.road.entity.cricket.court.log.LogCricketCourtChangeScore;
import com.yanqu.road.entity.cricket.court.log.LogCricketCourtRoundRank;
import com.yanqu.road.logic.bussiness.log.LogBussiness;

import java.util.ArrayList;
import java.util.List;

public class CrossCricketCourtLog {

    public static void save() {
        saveLogCricketCourtRoundRank();
        saveLogCricketCourtChangeScore();
    }

    private static List<LogCricketCourtRoundRank> logCricketCourtRoundRankList = new ArrayList<>();

    private static List<LogCricketCourtChangeScore> logCricketCourtChangeScoreList= new ArrayList<>();


    public static void addLogCricketCourtRoundRank(LogCricketCourtRoundRank log) {
        synchronized (logCricketCourtRoundRankList) {
            logCricketCourtRoundRankList.add(log);
        }
    }

    public static void saveLogCricketCourtRoundRank() {
        List<LogCricketCourtRoundRank> list;
        synchronized (logCricketCourtRoundRankList) {
            list = new ArrayList<>(logCricketCourtRoundRankList);
            logCricketCourtRoundRankList.clear();
        }
        if (list.isEmpty()) {
            return;
        }
        LogBussiness.addLogCricketCourtRoundRankList(list);
    }

    public static void addLogCricketCourtChangeScore(LogCricketCourtChangeScore log) {
        synchronized (logCricketCourtChangeScoreList) {
            logCricketCourtChangeScoreList.add(log);
        }
    }

    public static void saveLogCricketCourtChangeScore() {
        List<LogCricketCourtChangeScore> list;
        synchronized (logCricketCourtChangeScoreList) {
            list = new ArrayList<>(logCricketCourtChangeScoreList);
            logCricketCourtChangeScoreList.clear();
        }
        if (list.isEmpty()) {
            return;
        }
        LogBussiness.addLogCricketCourtChangeScoreList(list);
    }

}
